package com.emuporium.gymrat.server.exercise;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.emuporium.gymrat.server.data.ExerciseDB;

@SuppressWarnings("serial")
public class ExerciseDeleteServlet extends HttpServlet {
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		String[] deleteIdsString = request.getParameterValues("deleteBox");
		ArrayList<Integer> deleteIds = new ArrayList<Integer>();

		for (String s : deleteIdsString) {
			deleteIds.add(new Integer(s));
		}

		ExerciseDB.deleteExercises(deleteIds);

		request.setAttribute("redirecturl", "/exercise/list");
		String url = "/includes/redirect.jsp";
		RequestDispatcher dispatcher = getServletContext()
				.getRequestDispatcher(url);
		dispatcher.forward(request, response);
	}

}
